package cc.mrbird.demo.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author: chenhs
 * @date: Created in 16:28 2020/3/25
 **/
@Service
public class TestAsyncService {

    private Logger logger = LoggerFactory.getLogger(TestAsyncService.class);

    public void asyncMethod() {
        sleep();
        logger.info("异步方法内部的线程名称：{}", Thread.currentThread().getName());
    }

    public void syncMethod() {
        sleep();
    }

    private void sleep() {
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
